<template>
<Modal
	v-model="show"
	title="区域信息"
	:width="700"
	>
	<Form :model="info" :label-width="150" style="width: 100%" :rules="ruleValidate" ref="form">
		
		<Row>
			<Col>
				<FormItem label="区域名称：" prop="name">
					<Input v-model="info.name" placeholder="" style="width: 240px;"></Input>
				</FormItem>
			</Col>
			<Col>
				<FormItem label="缩写：" prop="sx_name">
					<Input v-model="info.sx_name" placeholder="" style="width: 240px;"></Input>
				</FormItem>
			</Col>
			<Col>
				<FormItem label="排序：" prop="sort">
					<Input v-model="info.sort" placeholder="" style="width: 240px;"></Input>
					<p style="color: #999;">请输入0-999整数，0为优先</p>
				</FormItem>
			</Col>
			<Col style="position: relative;top: -20px;">
				<FormItem label="是否显示：">
					 <i-switch v-model="info.is_enable" size="large" :true-value="1" :false-value="0"></i-switch>
				</FormItem>
			</Col>
		</Row>
		
	</Form>

	<div slot="footer" style="text-align: center;">
		<Button type="success" size="large" @click="handleSubmit('form')">提交</Button>
	</div>
</Modal>
</template>

<script>


export default {
  name: 'multicurrency_bar',
  data(){
	return {
		show:false,
		ruleValidate:{
			name:[
				{ required: true, message: '不能为空', trigger: 'blur' }
			],
			sx_name: [
				{ required: true, message: '不能为空', trigger: 'blur' },
			],
			sort: [
				{ required: true, message: '不能为空', trigger: 'blur' },
			],
		},
		def_info:{
			name:'',
			sx_name:'',
			sort:'10',
			is_enable:1,
			id:0
		},
		info:{
			name:'',
			sx_name:'',
			sort:'10',
			is_enable:1,
			id:0
		}
	};
  },
  props:['value','cinfo'],
  created(){
	this.show = this.value;
  },
  watch:{
	value(val){
		this.show = val;
	},
	show(val){
		this.$emit('input',val);
	},
	cinfo:{
		handler(val){
			
			if(typeof(val)!='object'){
				this.info = this._getData(this.def_info);
				return ;
			}
			
			for(var i in this.info){
				
				if(typeof(val[i])!='undefined'){
					this.info[i] = val[i];
				}
				else{
					this.info[i] = this.def_info[i];
				}
			}
			
			this.info.is_enable = parseInt(this.info.is_enable);
		},
		deep:true
	}
  },
  methods: {
	handleSubmit(name){
		var self = this;
		
		this.$refs[name].validate((valid) => {
			if (valid) {
				self.save();
			}
		})
	},
	save(){
		var self = this;
		var postdata = this.info;
		
		Whttp.load('User/Region/save',postdata, (res)=>{
			self.$Message.info('提交成功');
			self.show = false;
			self.$emit('success',res);
		});
	},
  }
}
</script>
<style scoped>

</style>